﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CodeTier.BUL;
using Source.ViewModels;

namespace Source.Controllers
{
    public class HomeController : Controller
    {
        //<
        // GET: /Home/

        //
        // GET: /Home/

        public ActionResult Index(int MaDM = -1)
        {
            List<SanPhamBUS> lstsp;
            string title = "";
            if (MaDM == -1)
            {
                title = "Sản Phẩm Mới Nhất";
                lstsp = SanPhamBUS.getAll().Take(6).ToList();
            }
            else
            {
                DanhMucBUS dm = DanhMucBUS.getByIdConvert(MaDM);
                title = "Sản Phẩm " + dm.TenDM;
                lstsp = SanPhamBUS.getAllByDanhMuc(MaDM);

            }
            List_SanPham displaysp = new List_SanPham(lstsp, title);
            return View(displaysp);
        }

        [ChildActionOnly]
        public PartialViewResult displayCategory()
        {
            List<DanhMucBUS> lstdm = DanhMucBUS.getAll();
            return PartialView(lstdm);
        }

    }
}
